package com.cos.hospital.ui.main.adapter;

import android.content.Context;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.widget.ProgressBar;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.cos.hospital.R;
import com.cos.hospital.code.Logic;
import com.cos.hospital.model.bean.PatientListBean;

import java.util.List;

/**
 * 接诊管理适配器
 * Created by yby on 2018/9/10
 */
public class ReceptionAdapter extends BaseQuickAdapter<PatientListBean.ItemsBean, BaseViewHolder> {
    public ReceptionAdapter(@Nullable List<PatientListBean.ItemsBean> data) {
        super(R.layout.item_reception, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, PatientListBean.ItemsBean item) {
        Context context = helper.itemView.getContext();
        helper.itemView.getContext();
//        UGlide.loadCirle(context, url, R.mipmap.ic_default_avatar, R.mipmap.ic_default_avatar, iv);
        helper.setText(R.id.tv_name, item.getFldPatientName());
        helper.setText(R.id.tv_age, item.getFldAge() + "岁");
        helper.setText(R.id.tv_gender, Logic.getSex(item.getFldPatientSex()));
        helper.setVisible(R.id.iv_wechat, item.getFldRegisterType() == 0);
        int fldState = item.getFldState();
        boolean visible;
        String state;
        int stateTextColorRes, stateBgRes;
        switch (fldState) {
            case 1:
                visible = true;
                state = "候诊中";
                stateBgRes = R.drawable.shape_status;
                stateTextColorRes = R.color.green_bg;
                break;
            case 2:
                visible = true;
                state = "已接诊";
                stateBgRes = R.drawable.shape_status_complete;
                stateTextColorRes = R.color.gray_state_complete;
                break;
            default:
                visible = false;
                state = "无状态";
                stateBgRes = R.drawable.shape_status_complete;
                stateTextColorRes = R.color.gray_state_complete;
                break;
        }
        helper.setVisible(R.id.tv_status, visible);
        helper.setText(R.id.tv_status, state);
        helper.setTextColor(R.id.tv_status, ContextCompat.getColor(context, stateTextColorRes));
        helper.setBackgroundRes(R.id.tv_status, stateBgRes);
        String fldDiagnose = item.getFldDiagnose();
        helper.setText(R.id.tv_diagnose, fldDiagnose == null ? "" : fldDiagnose);
        if (item.isSearchResult()) {
            helper.itemView.setBackgroundResource(R.color.search_light);
        } else {
            helper.itemView.setBackgroundResource(R.drawable.item_selector);
        }
        helper.addOnClickListener(R.id.tv_write);
        helper.addOnClickListener(R.id.tv_send);
        ProgressBar progressBar = helper.getView(R.id.remain_progress);
        int progress = item.getTreatmentNumber() * 100 / (item.getTreatmentTotal() == 0 ? 100 : item.getTreatmentTotal());
        progressBar.setProgress(progress);
        helper.setText(R.id.tv_num, item.getTreatmentNumber() + "/" + item.getTreatmentTotal());
    }
}
